using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum CannonLevel : short
{
    Weak = 0,
    Normal = 1,
    Strong = 2,
}

public class AirCannon : MonoBehaviour
{

    Vector3 originalPosition;
    Collider cannonCollider;
    float speed;
    float maxDistance;
    CannonLevel cannonLevel;
    void Start()
    {
        originalPosition = transform.position;
        cannonCollider = GetComponent<Collider>();
        speed = 5;
    }

    public void SetCannonLevel(CannonLevel level)
    {
        cannonLevel = level;
        switch (cannonLevel)
        {
            case CannonLevel.Weak:
                {
                    maxDistance = 6;
                    break;
                }
            case CannonLevel.Normal:
                {
                    maxDistance = 8;
                    break;
                }
            case CannonLevel.Strong:
                {
                    maxDistance = 12;
                    break;
                }
        }
    }

    void Update()
    {
        if (Vector3.Distance(transform.position, originalPosition) > maxDistance)
        {
            Destroy(gameObject);
        }
        RayForward();
        transform.position += speed * transform.forward * Time.deltaTime;
    }

    void RayForward()
    {
        Vector3 meshSize = GetComponent<MeshFilter>().mesh.bounds.size;
        float zlength = meshSize.z * transform.lossyScale.z;
        Vector3 rayOriginPos = new Vector3(transform.position.x, transform.position.y, transform.position.z + zlength);

        Debug.DrawLine(rayOriginPos, new Vector3(rayOriginPos.x, rayOriginPos.y, rayOriginPos.z + 0.3f), Color.red);

        RaycastHit hitinfo;
        if (Physics.Raycast(rayOriginPos, transform.forward, out hitinfo, 0.3f))
        {

        }
    }
}
